package main

import (
	"bytes"
	"fmt"
	"log"

	"golang.org/x/crypto/ssh"
)

func main() {
	// SSH 配置
	config := &ssh.ClientConfig{
		User: "mzydz",
		Auth: []ssh.AuthMethod{
			ssh.Password("ee."),
		},
		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
	}

	// 连接 SSH 服务器
	conn, err := ssh.Dial("tcp", "192.168.11.4:22", config)
	if err != nil {
		log.Fatalf("Failed to dial: %v", err)
	}
	defer conn.Close()

	// 创建一个新的会话
	session, err := conn.NewSession()
	if err != nil {
		log.Fatalf("Failed to create session: %v", err)
	}
	defer session.Close()

	// 执行命令
	var b bytes.Buffer
	session.Stdout = &b
	err = session.Run("df -h")
	if err != nil {
		log.Fatalf("Failed to run command: %v", err)
	}

	// 输出命令结果
	fmt.Println(b.String())
}
